package logic

import (
	"context"
	"github.com/SupenBysz/tt-demo/api"
	"github.com/SupenBysz/tt-demo/internal/model"
	"net/http"
	"strconv"
)

//创建考试成绩
func (s *SchoolLogic) CreateExamination (ctx context.Context, data api.CreateExaminationData)(resp *api.ApiRes,err error){
	resp = &api.ApiRes{}

	//查询员工信息是否存在
	id,err:=strconv.ParseInt(data.EmployeeId,0,64)
	if err != nil {
		resp.Msg = "员工信息不存在"
		resp.Code= http.StatusInternalServerError
		return
	}

	_,err=s.Modules.Employee().GetEmployeeById(ctx,id)
	if err != nil {
		resp.Msg = "员工信息不存在"
		resp.Code= http.StatusInternalServerError
		return
	}

	//插入考试信息
	_,err = s.Dao.Ctx(ctx).Insert(data)
	if err != nil {
		resp.Msg = err.Error()
		resp.Code= http.StatusInternalServerError
		return
	}


	return
}

//考试成绩查询
func (s *SchoolLogic) QueryExaminationByName (ctx context.Context, data *api.QueryExaminationByNameReq)(resp *api.ApiRes,err error){
	resp = &api.ApiRes{}

	result :=model.ExaminationList{}

	//考试信息查询
	err = s.Dao.Ctx(ctx).Where(map[string]string{"name":data.Name}).Scan(&result)
	if err != nil {
		resp.Msg = err.Error()
		resp.Code= http.StatusInternalServerError
		return
	}

	resp.Data = result

	return
}